package it.infodea.tapestrydea.components;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.BeanDisplay;
import org.apache.tapestry5.dom.Element;

@IncludeStylesheet(value = "../assets/styles/tapestrydea.css")
public class BeanDisplayDea extends BeanDisplay {
	
	/**
	 * The label of the header. The header is adding only if
	 * the label is setted.
	 */
	@Parameter(defaultPrefix = BindingConstants.LITERAL)
	@Property(write = false)
	private String headerLabel;

	/**
	 * If false the components isn't display. By default true.
	 */
	@Parameter
	private boolean visible = true;
	
	boolean beginRender(MarkupWriter writer) {
		if (visible && headerLabel != null) {
			Element e = writer.element("span");
			e.addClassName("dea-header");
			writer.writeRaw(headerLabel);
			writer.end();
		}
		return visible;
	}

}
